<template>
	<view class="page-box">
		<view class="select-bank-card" @click="bindCard">
			<text>{{!bankCardInfo.cardNumber ? '请绑定银行卡' : bankCardInfo.bankName+'('+bankCardInfo.cardNumber + ')'}}</text>
			<view class="allow-icon"></view>
		</view>
		<view class="money-input-box">
			<text class="money-title-box">提现金额</text>
			<text class="money-symbol-box">¥</text>
			<input class="money-value-box" v-model="bankCardInfo.money" placeholder="输入金额" />
		</view>
		<view class="step-btn-box" @click="saveClick">
			确定
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bankCardInfo: {
					bankName: '',
					cardNumber: '',
					money: ''
				}
			}
		},
		onShow() {
			let self = this
			uni.getStorage({
				key: 'bankInfo',
				success: function(res) {
					console.log(res)
					if(res){
						let bankInfo = JSON.parse(res.data)
						console.log(bankInfo)
						self.bankCardInfo.bankName = bankInfo.bank_name
						self.bankCardInfo.cardNumber = bankInfo.card_no
					}else{
						this.bindCard()
					}
				},
				fail: function(res) {
					this.bindCard()
					self.bankCardInfo.bankName = ''
					self.bankCardInfo.cardNumber = ''
				},
			});
		},
		methods: {
			bindCard() {
				uni.navigateTo({
					url: '/pages/bindNewCard/bindNewCard'
				});
			},
			saveClick() {
				let req = /^[0-9]+\.?[0-9]{0,2}$/
				if (req.test(this.bankCardInfo.money)) {
					let params = {
						money: this.bankCardInfo.money
					}
					this.$http.post('addons/shopro/user_wallet_apply/apply', params).then((res) => {
						console.log(res)
						uni.showToast({
							title: res.msg || '提现成功',
							icon: 'success',
							duration:2000
						})
						setTimeout(()=>{
							console.log('aaa')
							uni.redirectTo({
								url: '/pages/home/home'
							});
						},2000)
					}).catch((err) => {
						uni.showToast({
							title: err.data.msg || '提现失败',
							icon: 'none'
						})
					})
				} else {
					uni.showToast({
						title: "请输入正确提现金额",
						icon: 'none'
					})
				}
			}
		}
	}
</script>

<style>
	.page-box {
		width: 100%;
		height: 100%;
	}

	.select-bank-card {
		height: 54px;
		margin-left: 16px;
		width: calc(100% - 32px);
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1px solid #E5E5E5;
		font-size: 16px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #010101;
	}

	.allow-icon {
		width: 7px;
		height: 13px;
		background: url(../../static/allow-icon.png);
		background-size: 100% 100%;
	}

	.money-input-box {
		height: 54px;
		margin-left: 16px;
		width: calc(100% - 32px);
		display: flex;
		align-items: center;
		border-bottom: 1px solid #E5E5E5;
	}

	.money-title-box {
		font-size: 16px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #010101;
		margin-right: 16px;
	}

	.money-symbol-box {
		font-size: 16px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #010101;
	}

	.money-value-box {
		margin-left: 8px;
		width: calc(100% - 120px);
	}

	.step-btn-box {
		position: absolute;
		left: 16px;
		bottom: 24px;
		height: 46px;
		width: calc(100% - 32px);
		line-height: 46px;
		text-align: center;
		background: #010101;
		border-radius: 23px;
		font-size: 18px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
	}
</style>
